#include "MyString.h"
#include<iostream>
using namespace std; 

MyString::MyString() {
	pM = '\0';
	mSize = 0;
}
MyString::MyString(int n, char c) {
	pM = new char[n + 1];
	for (int i = 0; i < n; i++) {
		pM[i] = c;
	}
	pM[n] = 0;
	mSize = n;
}
MyString::MyString(int n, char *s) {
	pM = s;
	mSize = n;
}
MyString::MyString(const MyString &str) {
	if (pM != NULL) {
		free(pM);
		pM = NULL; 
	}
	pM = new char[str.mSize+1];
	for (int i = 0; i <= str.mSize; i++) {
		pM[i] = str.pM[i];
	}
	mSize = str.mSize;
}
//MyString & MyString::operator=(const MyString &str) {
//
//}
MyString::~MyString() {
	if (pM != NULL) {
		delete[] pM;
		pM = NULL; 
	}
}

MyString * MyString::operator+(const MyString &str) {
	char * s = new char[mSize + str.mSize+1];
	strcpy(s, pM);
	strcpy(s+mSize, str.pM);
	MyString *ms = new MyString(strlen(s), s);
	return ms; 
}
MyString * MyString::operator+(const char *str) {
	char * s = new char[mSize + strlen(str) + 1];
	strcpy(s, pM);
	strcpy(s + mSize, str);
	MyString *ms = new MyString(strlen(s), s);
	return ms;
}
MyString & MyString::operator+=(const MyString &str) {
	int newLen = mSize + str.mSize + 1;
	char * newStr = new char[newLen];
	strcpy(newStr, pM);
	strcpy(newStr+mSize, str.pM);
	delete[] pM;
	pM = newStr;
	mSize = newLen;
}
MyString & MyString::operator+=(const char *c) {

}








